﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：ContactsList.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：通讯录的查看（包括通过类别查询）
 * 作者：侯建
 * 创建日期：2011.04.07
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.Default.server.MessageBoard;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Jxym.Common.JSON;

namespace Jxym.wlkc2011.Module.Default.server.Contacts
{
    public partial class ContactsList : System.Web.UI.Page
    {
        MsSqlDal<model.Contacts> iCom = new MsSqlDal<model.Contacts>();
        //MsSqlDal<model.Contacts> iCom = new MsSqlDal<model.Contacts>();
        PageBean pb = null;
        private string Key = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["limit"] != null && Request.Params["start"] != null)
            {
                int start = Convert.ToInt32(Request.Params["start"]);
                int limit = Convert.ToInt32(Request.Params["limit"]);
                //判断树形菜单相关联的信息
                if (Request.Params["ClassID"] != null)
                {
                    int classid = Convert.ToInt32(Request.Params["ClassID"]);
                    IList<model.Contacts> list = iCom.GetPageList("AddUser = " + Jxym.Common.Request.AdminID("user") + "and ContactsType = " + classid.ToString(), null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                    pb = new PageBean();
                    pb.Count = iCom.GetPageCount("AddUser = " + Jxym.Common.Request.AdminID("user") + "and ContactsType = " + classid.ToString(), null);
                    pb.List = list;
                    Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                }
                else
                {

                    if (Request.Params["key"] != null)
                    {
                        Key = Request.Params["key"].ToString();
                        pb = new PageBean();
                        IList<model.Contacts> list = iCom.GetPageList("AddUser = " + Jxym.Common.Request.AdminID("user") + " and ContactsName like '%" + Key + "%'", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        pb.Count = iCom.GetPageCount("AddUser = " + Jxym.Common.Request.AdminID("user") + " and ContactsName like '%" + Key + "%'", null);
                        pb.List = list;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                    else
                    {
                            pb = new PageBean();
                            IList<model.Contacts> list = iCom.GetPageList("AddUser = " + Jxym.Common.Request.AdminID("user"), null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                            pb.Count = iCom.GetPageCount("AddUser = " + Jxym.Common.Request.AdminID("user"), null);
                            pb.List = list;
                            Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                }
            }
            else
            {
                Response.Write("{'Count':0,'List':[]}");
            }
        }
    }
}